home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#44 (May 89)
/
Forth Stuff
/
V5#5 SysEnvirons
< prev
Wrap
Text File
|
1989-03-15
|
8KB
|
321 lines
\ System configuration cdev
\ Example for MacTutor written in Mach2 Forth
\ J.Langowski March 1989
only forth also mac also assembler
\ Define SysEnvirons trap; not present in Mach2.14 release
\ alternatively, use the trap compiler accessible on the
\ GEnie Mach2 libraries
.TRAP _SysEnvirons $A090
0 CONSTANT environsVersion
2 CONSTANT machineType
4 CONSTANT systemVersion
6 CONSTANT processor
8 CONSTANT hasFPU
9 CONSTANT hasColorQD
10 CONSTANT keyBoardType
12 CONSTANT atDrvrVersNum
14 CONSTANT sysVRefNum
\ compiler support words for kernel-independent definitions,
\ defproc resources, etc.
\ :xdef compiles a JMP at the beginning of the
\ block, which is resolved at the end of the definition
\ by ;xdef.
: :xdef ( -- branch marker )
create -4 allot
$4EFA w, ( JMP )
0 w, ( entry point to be filled later )
0 , ( length of routine to be filled later )
here 6 - 76543 ( marker for stack checking )
;
: ;xdef { branch marker entry | -- }
marker 76543 <> abort" xdef mismatch"
entry branch - branch w!
here branch - 2+ branch 2+ !
;
: xlen 4 + @ ; ( get length word of external definition )
\ **** cdev proc glue macros for kernel-independent code
CODE cdev.prelude
LINK A6,#-512 ( 512 bytes of local Forth stack )
MOVEM.L A0-A5/D0-D7,-(A7) ( save registers )
MOVE.L A6,A3 ( setup local loop return stack )
SUBA.L #256,A3 ( in the low 256 local stack bytes )
MOVE.L 8(A6),D0 ( CPDialog )
MOVE.L 12(A6),D1 ( cdevValue )
MOVE.L 16(A6),D2 ( theEvent )
CLR.L D3
MOVE.W 20(A6),D3 ( CPanelID )
EXT.L D3 ( in case this is negative )
CLR.L D4
MOVE.W 22(A6),D4 ( numItems )
CLR.L D5
MOVE.W 24(A6),D5 ( Item )
CLR.L D6
MOVE.W 26(A6),D6 ( message )
MOVE.L D6,-(A6)
MOVE.L D5,-(A6)
MOVE.L D4,-(A6)
MOVE.L D3,-(A6)
MOVE.L D2,-(A6)
MOVE.L D1,-(A6)
MOVE.L D0,-(A6)
RTS \ just to indicate the MACHro stops here
END-CODE MACH
CODE cdev.epilogue ( resCode -- )
MOVE.L (A6)+,D0
MOVE.L D0,28(A6) ( store function result )
MOVEM.L (A7)+,A0-A5/D0-D7 ( restore registers )
UNLK A6
MOVE.L (A7)+,A0 ( return address )
ADD.W #20,A7 ( pop off 20 bytes of parameters )
JMP (A0)
RTS
END-CODE MACH
\ the actual cdev code starts here.
\ REMEMBER: don't use CALL for the toolbox routines;
\ use (CALL) instead, which is not dependent on D4
\ pointing to a correct stack.
:xdef myCdev
\ just to put some text into the resource
\ for easier identification
: start " Mach2 Forth cdev example, JL/MacTutor 1989" ;
CODE SysEnvirons ( theWorld versrequested -- theWorld resCode )
MOVEA.L 4(A6),A0
MOVE.L (A6)+,D0
ADDQ.L #4,A6
_SysEnvirons
MOVE.L A0,-(A6)
EXT.L D0
MOVE.L D0,-(A6)
RTS
END-CODE
\ words which extract single items from the SysEnvRec
: ?mach { | [ 12 lallot ] sysEnvRec -- machine# }
^ sysEnvRec 1 SysEnvirons drop 2+ w@ ;
: ?sys { | [ 12 lallot ] sysEnvRec -- system# revision# }
^ sysEnvRec 1 SysEnvirons drop
dup 5 + c@ swap 4+ c@ ;
: ?proc { | [ 12 lallot ] sysEnvRec -- machine# }
^ sysEnvRec 1 SysEnvirons drop 6 + w@ ;
: ?fpu { | [ 12 lallot ] sysEnvRec -- machine# }
^ sysEnvRec 1 SysEnvirons drop 8 + c@ ;
: ?colorQD { | [ 12 lallot ] sysEnvRec -- machine# }
^ sysEnvRec 1 SysEnvirons drop 9 + c@ ;
: ?keyType { | [ 12 lallot ] sysEnvRec -- machine# }
^ sysEnvRec 1 SysEnvirons drop 10 + w@ ;
: ?atkVers { | [ 12 lallot ] sysEnvRec -- machine# }
^ sysEnvRec 1 SysEnvirons drop 12 + w@ ;
: ?sysVRef { | [ 12 lallot ] sysEnvRec -- machine# }
^ sysEnvRec 1 SysEnvirons drop 14 + w@ l_ext ;
\ factored out the GetDItem/SetIText stuff
: set.item ( string dlgPtr #item ) { | type hItem box -- }
^ type ^ hItem ^ box (call) GetDItem
hItem swap (call) SetIText ;
\ display system characteristics
\ in the cdev dialog box (DITL -4064 resource dependent)
\ the strings are hard-coded, but could as well be contained
\ in a STR# resource
: display.it { numItems dlgPtr | [ 16 lallot ] str1 -- }
?mach CASE
0 OF " unknown" ENDOF
1 OF " Mac 512KE" ENDOF
2 OF " Mac Plus" ENDOF
3 OF " Mac SE" ENDOF
4 OF " Mac II" ENDOF
5 OF " Mac IIx" ENDOF
\ wasn't sure whether machine=6 is the new baby MacII,
\ so left out that case
7 OF " Mac SE/030" ENDOF
" NEW MACHINE"
ENDCASE dlgPtr 3 numItems + set.item
\ get system version # and convert to string, format X.XX
\ if you don't know Forth, this might be hard to read :-)
?sys
^ str1 swap (call) numtostring
dup c@ 1+ + swap (call) numtostring
dup c@ 1 = IF dup 1+ c@ over 2+ c!
dup 1+ ascii 0 swap c! THEN
ascii . swap c!
^ str1 dup c@ 3 + swap c!
^ str1 dlgPtr 5 numItems + set.item
?proc CASE
0 OF " unknown" ENDOF
1 OF " 68000" ENDOF
2 OF " 68010" ENDOF
3 OF " 68020" ENDOF
4 OF " 68030" ENDOF
" NEW"
ENDCASE dlgPtr 7 numItems + set.item
?fpu IF " yes" ELSE " none" THEN
dlgPtr 9 numItems + set.item
?colorQD IF " yes" ELSE " no" THEN
dlgPtr 11 numItems + set.item
?keyType CASE
0 OF " unknown type" ENDOF
1 OF " 'old' Macintosh keyboard" ENDOF
2 OF " 'old' Macintosh keyboard with keypad" ENDOF
3 OF " Macintosh Plus keyboard" ENDOF
4 OF " Apple Desktop Bus extended keyboard" ENDOF
5 OF " Apple Desktop Bus standard keyboard" ENDOF
" something NEW"
ENDCASE dlgPtr 13 numItems + set.item
^ str1 ?atkVers (call) numtostring
dlgPtr 15 numItems + set.item
;
: testCdev { message item numItems CPanelID
theEvent cdevValue CPDialog -- result }
\ we only need to respond to the initDev message
\ by putting the system configuration info
\ into the cdev's dialog items
message CASE
0 OF ( initDev ) 1 (call) sysbeep
numItems CPDialog display.it ENDOF
( insert handlers for other messages here)
ENDCASE
cdevValue \ everything OK: return old cdevValue
;
: cdev.glue
cdev.prelude
testCdev
cdev.epilogue
;
' cdev.glue ;xdef
\ end of cdev code
\ making the cdev resource, the usual way
: $create-res call CreateResFile call ResError L_ext ;
: $open-res { addr | refNum -- result }
addr call openresfile -> refNum
call ResError L_ext
dup not IF drop refNum THEN
;
: $close-res call CloseResFile call ResError L_ext ;
: make-cdev { | refNum -- }
" cdev.res" dup $create-res
abort" You have to delete the old 'cdev.res' file first."
$open-res dup -> refNum call UseResFile
['] myCdev dup xlen
call PtrToHand drop ( result code )
ASCII cdev -4064 " cdev JL" call AddResource
refNum $close-res drop ( result code )
;
\ End of cdev creation code.
\ Following are some words that can be executed
\ from within the Mach2 system, and output system configuration
\ information directly to the console.
: myMachine cr ." This is a"
?mach CASE
0 OF ." n unknown machine," ENDOF
1 OF ." Mac 512KE," ENDOF
2 OF ." Mac Plus," ENDOF
3 OF ." Mac SE," ENDOF
4 OF ." Mac II," ENDOF
5 OF ." Mac IIx," ENDOF
7 OF ." Mac SE/030," ENDOF
." NEW MACHINE,"
ENDCASE
;
: mySystem ?sys
." running system v. "
<# # #> type ascii . emit
<# # # #> type ascii . emit
;
: myProcessor cr ." It uses a"
?proc CASE
0 OF ." n unknown" ENDOF
1 OF ." 68000" ENDOF
2 OF ." 68010" ENDOF
3 OF ." 68020" ENDOF
4 OF ." 68030" ENDOF
." NEW"
ENDCASE
." processor"
;
: myFPU ?fpu IF
ascii , emit cr
." and has an arithmetic coprocessor installed."
ELSE
ascii . emit
THEN
;
: myCQD cr ." Color QuickDraw is "
?colorQD 0= IF ." not " THEN
." available."
;
: myKeyBoard cr ." The Keyboard is "
?keyType CASE
0 OF ." of an unknown type." ENDOF
1 OF ." the 'old' Macintosh type." ENDOF
2 OF ." the 'old' Macintosh type with keypad." ENDOF
3 OF ." the Mac Plus type." ENDOF
4 OF ." the ADB extended type." ENDOF
5 OF ." the standard ADB type." ENDOF
." a NEW type."
ENDCASE
;
: myAtkDrvr cr ." Appletalk v. " ?atkVers .
." is installed."
;
: machTest
myMachine mySystem
myProcessor myFPU
myCQD
myKeyBoard
myAtkDrvr
cr
;